import React from 'react'
import {getUploadUrl} from "../../constant/upload-url";
import {Button,message} from "antd";
import {FormattedMessage} from "react-intl";
import {TwsReactMarkdownEditor} from 'tws-antd'
import {convertContent} from "../../constant/lang-util";

export default class QuizSuggestionBox extends React.Component {
  state = {
    isVisible: false,
    content: ''
  }
  submit = () => {
    const {submit, quiz} = this.props
    const {content} = this.state
    submit({
      quizId: quiz.id,
      organizationId: quiz.organizationId,
      content,
      type: 'HOMEWORK_QUIZ'
    },()=>{
      message.success(convertContent('提交成功'))
      this.setState({isVisible:false})
    })
  }

  render() {
    const {isVisible, content} = this.state
    const {settings} = this.props
    return <div className='margin-b-3'>
      <a onClick={() => this.setState({isVisible: !isVisible})}><FormattedMessage id='题目有错误'/></a>
      {
        isVisible
          ? <div>
            <TwsReactMarkdownEditor
              action={getUploadUrl(settings.appContextPath)}
              value={content}
              onChange={content => this.setState({content})}/>
            <Button className='margin-t-2'
                    onClick={this.submit}
                    type='primary'>
              <FormattedMessage id='提交反馈'/>
            </Button>
          </div>
          : ''
      }
    </div>

  }
}